package binary_tree.leetcode;

/**
 * 判断是否是相同的树
 * @Author Stark
 * @Date 2022/2/22 10:03
 */
public class Num100_SameTree {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        //都为空表示之前的结点判断完了,返回true
        if(p == null && q == null){
            return true;
        }
        //两者都为空的条件已经判断过了,满足其他情况的都为假
        if(p == null || q == null){
            return false;
        }
        //判断两个结点的值是否是相等的
        if(p.val != q.val){
            return false;
        }
        return isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }
}
